<?php
require_once('PHPUnit/Framework.php');
require_once("../SMTransmitter/SMTransmitter.class.php");
require_once("../SMTransmitter/Reporter.interface.php");
require_once("../SMTransmitter/CurlReporter.class.php");
require_once("../SMTransmitter/SMMessage.class.php");
require_once("../SMTransmitter/Converter.class.php");

class ConverterTest extends PHPUnit_Framework_TestCase{
    private $dao=null;
    private $package=null;

    protected function setUp(){
        $this->dao = new SerializePackageConverter();

        // intialize SMMessagePackage with mock data objects
        $this->package = new SMMessagePackage("application_key", "transmitter_base_url");
        $this->package->addSMMessage(new SMMessage("errno", "errstr", "errfile", "errline"));
        $this->package->addSMMessage(new SMMessage("errno", "errstr", "errfile", "errline"));
        $this->package->addSMMessage(new SMMessage("errno", "errstr", "errfile", "errline"));
    }

    public function testConvert(){
        $result = unserialize($this->dao->convert($this->package));
        
        $this->assertEquals(count($result), 3, "error: data mangled.");
        $this->assertEquals($result['transmitter_base_url'], "transmitter_base_url", "error: data mangled.");
        $this->assertEquals($result['application_key'], "application_key", "error: data mangled.");
        $this->assertEquals(count($result['messages']), 3, "error: data mangled.");
    }

    public function testConvertSMMessages(){
        $sm_messages = array(new SMMessage("errno", "errstr", "errfile", "errline"),
                          new SMMessage("errno", "errstr", "errfile", "errline"),
                          new SMMessage("errno", "errstr", "errfile", "errline"),
                          new SMMessage("errno", "errstr", "errfile", "errline"));

        $result = $this->dao->convertSMMessages($sm_messages);
        $this->assertEquals(count($result), 4, "error: data mangled.");
    }
}

?>